#LinuxClient
| Command | Description |
|---|---|
ex |
execute |
ps |
see active operations |
kill |
close apps |
grep |
to see active processes |
-9 |
to force closing |
dash |
text editor |
exit |
to leave |
pwd |
show the current directory |
history |
all the commands entered |
ctrl + r |
to reverse search the commands entered in the history |
-c |
to clear |
history -c |
to clear the history |
ls -a |
list all +hidden files |
ls -ar |
list all files read-only |
ctrl + l |
clear the screen |
ctrl + w |
clear the last word |
ctrl + d |
to close the terminal |
shift + Page Up / Down |
to go up / down in the page |
ctrl + a / ctrl + e |
go to the beginning of the line / go to end |
ctrl + y |
undo the last action |
tree |
to see directories in a more organized manner |
ls -alR |
see all the repertories |
-h |
humanized version, like changing bytes to gigabytes etc |
which firefox |
to find the directory of firefox |
firefox & |
to start firefox and continue working on the terminal not being related to the app launched (firefox in this case) |
kill 56846 (process number of firefox) |
to close firefox by the process number we acquire with the previous command |
cat |
display the contents of a document |
grep -w war file_name |
search war in file_name document, for example search for root in auth.log |
| more |
to see only the content filling the page |
| less |
to see the content and being able to go up and down |
d / b (while in less) |
go / go back 10 lines |
y (while in less) |
go down 1 line |
/"search_term" (while in less) |
to search certain terms in less we click / and write the term |
n (while in less and searching a term) |
to display the next searched term line |
/term1.*term2 (while in search in less) |
to search 2 different terms in a line |
head -n 3 syslog |
see the first 3 lines of syslog |
tail syslog |
see the last 10 lines of syslog |
tail -f syslog |
follow the current activities and log them |
sudo dhclient |
ipconfig /release and /renew and does DHCP DORA, Discover, Offer, Request, Acknowledge |
| ![[Pasted image 20240320102340.png]] | |
-r |
to force, reload |
cd + enter |
cd and space and enter goes to user's home |
touch |
to open a file, if the file doesn't exist, it creates it |
-F |
see files in an organized manner |
mkdir |
create a directory |
rmdir |
remove a directory |
mkdir tt/tt1/tt2 |
to create subdirectories |
cp |
to copy files and directories |
mv |
move files and directories or change/replace the file name |
cp file filecopy |
to copy 'file' as 'filecopy' name |
cp file myfile/ |
to copy 'file' inside the myfile directory |
-v |
to see the confirmation of the action done |
rm -r myfiles/testfiles |
to remove directory (if it's empty) |
ln |
to link files, creates a second file linked to the first one |
nano |
for text editor |
-i |
to see the inode (which number does the file has in the harddisk) |
cat |
view the content of the file |
ln -s |
to create an alias / shortcut |
-ali |
see details with inode, all, writing rights |
sudo su |
to pass to the root account and stay there, gives # at the end |
neofetch |
to see all details of the system like version info, should apt install it first |
ls -al |
view rights, users, groups, directories |
cd ../.. |
to go to the first directory in the path |
ps guaxf |
to see active services, or kill them |
uname -r |
to see the current linux kernel version |
User accounts
| Command | Description |
|---|---|
adduser |
creates a new user in the system |
sudo su |
pass to the root account and stay |
passwd patrick |
change the password of patrick |
deluser |
delete a user, but doesn't delete the group |
cat /etc/group- |
to see the user groups |
nano /etc/group- |
to delete the group of the user (in our case; patrick) |
deluser --remove-home patrick |
to delete user completely and it's files/directory |
usermod |
modify a user |
addgroup |
add a group |
usermod -g amis admin3(username) |
change the group of a user |
usermod -aG amis,paris,tssr patrick |
add patrick to these 3 groups |
chown |
change the owner (user level) of a file |
chg |
to change password or group |
chgrp |
change the group |
sudo chown admin3:admin3 fichier1.txt |
change owner and the group of the fichier1.txt to be the admin3 |
-R |
heritage, all the sub-directories obtain the same rights |
sudo chown -R admin3:admin3 /home/patrick/ |
change all the rights of the patrick user's file to admin3. in this case patrick cannot access to his account |
chmod 644 fichier1.txt |
change the rights of fichier1.txt to be -rw-r--r-- |
chmod g+w fichier1.txt |
change the group rights of the fichier1.txt , add write right |
chmod o-r fichier1.txt |
change the other's rights of the fichier1.txt, remove the writing right |
chmod u+x fichier1.txt |
when we give x to a file, we make it executable. when we edit it to be a script |
./fichier1.txt |
to execute the script |
echo $HOME |
show the directory of the home file |
sudo apt clean |
cleans the system, cleans the unnecessary small files |
sudo apt purge |
to force and clean everything that might have stayed from a program |
locate |
finds the location of a file, doesn't work with * **. ** *, should update, doesn't work very good, find is way better |
| FIND | |
find |
powerful tool to search. |
find -name "firefox" |
to search only the files that has this name |
find /var/log/ -name "syslog" |
find in a certain directory |
sudo find / -name "syslog" |
searches in the root |
find -name "*.txt" -atime -7 |
atime for accessing time stamp, -7 for the last 7 days |
sudo find /var/log "syslog" -type d |
type d to list only directories |
find . -name "*.txt" -printf "%p - %u\n" |
. to start from the current directory, printf for the results, %u for the user who created it, n for the name of the user |
sudo find / -name "*.tmp" -delete |
delete all the files with this name *.tmp |
find -name "*.txt" -exec chmod 600 {} \; |
find all these files and chmod their their rights |
| GREP | |
grep |
for filtering files, shows the words/word-groups even inside the files as lines |
grep alias .bashrc |
colors the alias lines in all the .bashrc files |
grep -i -n alias .bashrc |
shows the line numbers and doesn't take into account minuscule or majuscule letters |
| SORT | |
sort names.txt |
sorts the content of the file, doesn't modify it, just shows !! |
sort -o noms_tries.txt noms.txt |
-o for output, to modify it |
sort -r names.txt |
-r for inversing the list |
sort -R names.txt |
-R for shuffling the list |
sort -n numbers.txt |
-n for sorting the numbers in increasing order |
| --- | |
wc names.txt |
word count for the file. 8 8 64 names.txt first ; number for lines, second ; number of words, third ; number of letters. |
uniq doublons.txt |
display the result as all the duplicates deleted |
uniq doublons.txt sans_doublons.txt |
creates a new file without the duplicates |
uniq -c doublons.txt |
-c counts the duplicate numbers |
uniq -d doublons.txt |
shows only the duplicated values once |
cut -c 2-5 names.txt |
shows only between the 2nd and 5th letters in the value |
cut 1er-lettre |
only shows the first letter of each value |
cut -d , -f 1 notes.csv |
-d to indicate the separator ( , in our case), -f to indicate the number of the column |
libreoffice --calc notes.csv |
to see the columns in the calculator or excel |
cut -d , -f 2-4 notes.csv |
shows the results of the values between 2nd and 4th columns |
cut -d , -f 3- notes.csv |
shows the results of the values starting from the 3rd column and anything after |
cut -d , -f 1 notes.csv > eleves.txt |
create a new .txt with the first column's values, override or create |
cut -d , -f 1 notes.csv >> eleves.txt |
add the values at the end of the values if there are 2 >>. |
An example script we have made; ![[Pasted image 20240320163546.png]]
In the list first column is users, second is groups ![[users and groups in linux 2.png]]
Zip & RAR
| Command | Description |
|---|---|
tar -cvf nom_archive.tar nom_dossier/ |
create a .tar with a certain file/directory -c : to create a tar archive -v : to display the details of the action -f : to get the archive at one piece in a file |
tar -tf images.tar |
to see the contents of the file |
tar -rvf images.tar fichier_supplementaire.jpg |
add an extra file inside the archive |
System Monitoring & Surveillance
| Command | Description |
|---|---|
ps -ef |
to see the active processes |
kill -9 (process number) |
stop the process directly |
firefox& |
see the process number of firefox |
killall firefox-bin |
to kill the process with the name |
ps -e | firefox |
to see the process name of firefox |
sudo halt |
to stop the system |
sudo reboot |
to reboot the system |